package com.wn.controller;

import com.wn.annotation.RequireRoles;
import com.wn.entity.Catering;
import com.wn.service.CateringService;
import com.wn.utils.PageParam;
import com.wn.utils.Rsp;
import com.wn.utils.SystemControllerLog;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;

/**
 * (Catering)表控制层
 *
 * @author makejava
 * @since 2020-10-26 09:28:42
 */
@RestController
@RequestMapping("catering")
public class CateringController {
    /**
     * 服务对象
     */
    @Resource
    private CateringService cateringService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Catering selectOne(String id) {
        return this.cateringService.queryById(id);
    }

    /**
     * 动态查询
     * @param cateringPageParam
     * @return
     */
    @SystemControllerLog(description = "分页查询酒店信息")
    @PostMapping("/searchSomeCateringByPage")
    @RequireRoles(roles = {"admin","super_admin","reception","guide","tourist"},index = 1)
    @ApiOperation("查询所有 支持 多条件 分页 排序 查询")
    public Rsp searchSomeByPage(@RequestBody PageParam<Catering> cateringPageParam,
                                @RequestHeader("token") String token){
        return Rsp.success(cateringService.searchSomeByPage(cateringPageParam));
    }

    @SystemControllerLog(description = "修改酒店信息")
    @RequireRoles(roles = {"super_admin","admin"},index = 1)
    @PostMapping("/updateCatering")
    @ApiOperation("动态修改")
    public Rsp updateCatering(@RequestBody @Valid Catering catering,@RequestHeader("token") String token){

        //catering.setUpdatauserid("1");
        catering.setUpdatatime(new Date());
        return cateringService.update(catering) == 1?Rsp.success(null).msg("修改成功"):Rsp.fail().msg("修改失败");
    }

    @SystemControllerLog(description = "逻辑删除酒店信息")
    @RequireRoles(roles = {"super_admin","admin"},index = 1)
    @PostMapping("/deleteCateringLogical")
    @ApiOperation("逻辑删除")
    public Rsp deleteCateringLogical(@RequestBody Catering catering,@RequestHeader("token") String token){

        catering.setIsdeleted(1);

        return cateringService.update(catering) == 1?Rsp.success(null).msg("删除成功"):Rsp.fail().msg("删除失败");
    }
    @SystemControllerLog(description = "添加单个酒店信息")
    @RequireRoles(roles = {"super_admin","admin"},index = 1)
    @PostMapping("/addOneCatering")
    @ApiOperation("添加单个")
    public Rsp addOne(@RequestBody @Valid Catering catering,@RequestHeader("token") String token){

        //catering.setCreateuserid("1");
        catering.setCreatetime(new Date());
        return cateringService.insert(catering) == 1?Rsp.success(null).msg("添加成功"):Rsp.fail().msg("添加失败");
    }

    @GetMapping("selCatering")
    public List<Catering> selcatering(Object longitude,Object latitude){
        List<Catering> catering = cateringService.selcatering(longitude, latitude);
        return catering;
    }
}

